package com.rentong.wx.cust.controller;

import com.rentong.common.R;
import com.rentong.wx.cust.dto.ServiceTimeDto;
import com.rentong.wx.cust.service.CustUserServiceTimeService;
import com.rentong.wx.utils.WxApiUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author zhangle
 * @email 459343178@qq.com
 * @date 2024-12-24 14:42:31
 */
@RestController
public class CustUserServiceTimeController {

    @Autowired
    private CustUserServiceTimeService custUserServiceTimeService;


    //109、师傅设置时个人资料时的可约时间（接口有问题，可能已废弃）
    @GetMapping("/custUserServiceTime/getServiceTime")
    public R getServiceTime(HttpServletRequest request) throws Exception {
        return R.success(custUserServiceTimeService.getServiceTime(WxApiUtil.getCurrentCustId(request)));
    }

    //217、查询师傅设置的可约时间（算上本月，最近6个月的）
    @GetMapping("/custUserServiceTime/getChefServiceTime")
    public R getChefServiceTime(Long custId, HttpServletRequest request) throws Exception {
        //查师傅自己的可约时间，传0，用户单点师傅的场景，传师傅的custId
        if ("0".equals(custId.toString())) {
            custId = WxApiUtil.getCurrentCustId(request);
        }
        return R.success(custUserServiceTimeService.getChefServiceTime(custId));
    }


    //110、师傅服务时间设置
    @PostMapping("/custUserServiceTime/saveServiceTime")
    public R saveServiceTime(HttpServletRequest request, @RequestBody List<ServiceTimeDto> serviceTimeDto) throws Exception {
        custUserServiceTimeService.saveServiceTime(WxApiUtil.getCurrentCustId(request), serviceTimeDto);
        return R.success();
    }

    //111、师傅已经设置的服务时间列表（接口有问题，可能已废弃）
    @GetMapping("/custUserServiceTime/getServiceTimeList")
    public R getServiceTimeList(HttpServletRequest request) throws Exception {
        return R.success(custUserServiceTimeService.getServiceTimeList(WxApiUtil.getCurrentCustId(request)));
    }


    //132、取消可约时间
    @PostMapping("/custUserServiceTime/deleteServiceTime")
    public R deleteServiceTime(@RequestBody List<Long> ids) {
        custUserServiceTimeService.deleteServiceTime(ids);
        return R.success();
    }
}
